package com.jzo2o.customer.controller.consumer;

import cn.hutool.core.bean.BeanUtil;
import com.jzo2o.common.model.CurrentUserInfo;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.BankAccountService;
import com.jzo2o.mvc.utils.UserContext;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 11394
 * @version 1.0
 * @description: TODO
 * @date 2024/8/19 21:14
 */
@RestController
@RequestMapping("/worker/bank-account")
@Api(tags = "服务端 - 银行相关接口")
public class BankAccountController {

    @Resource
    BankAccountService bankAccountService;

    /**
    * @description
    * @author Gaosir
    * @return * @return: null
    * 新增或更新银行账号信息接口
    * @date 2024/8/19 21:17
    */
    @PostMapping()
    public void updateorsave(@RequestBody BankAccountUpsertReqDTO bankAccountUpsertReqDTO){

        //获取登录的id和类型
        CurrentUserInfo currentUserInfo = UserContext.currentUser();
        bankAccountUpsertReqDTO.setType(currentUserInfo.getUserType());
        bankAccountUpsertReqDTO.setId(currentUserInfo.getId());

        bankAccountService.updateorsave(bankAccountUpsertReqDTO);
    }

    /**
    * @description
    * @author Gaosir
    * @return * @return: null
    *  获取当前用户银行账号
    * @date 2024/8/19 22:25
    */
    @GetMapping("/currentUserBankAccount")
    public BankAccountResDTO querybank(){

        Long aLong = UserContext.currentUserId();
        BankAccount byId = bankAccountService.getById(aLong);
        BankAccountResDTO bankAccountResDTO = BeanUtil.toBean(byId, BankAccountResDTO.class);

        return bankAccountResDTO;
    }


}
